$(function(){
	var admin_id = getCookie('admin_id');
	if(!admin_id){
		window.location.replace('login.html');
	}
	var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
	//提交表单
   $("#submit_goods").click(function(){
   		 if($("#bar_code").val() !='' || $("#name").val() !='' || $("#mnemonic").val() !=''){
   		 	var query = $("#signupForm").serialize();
            $.ajax({
				url: ApiUrl + "/goods?"+query,
		        type: 'get',
		        dataType: 'JSON',
		        success: function(result) {
		        	if(result.code == 200){
		        		if(result.data.total == 0){
		        			parent.layer.msg("没搜到您想要的商品，请重新输入！");
		        			return false;
		        		}else{
		        			$("#goods").show();
		        			var html='<option value="0">---请选择---</option>';
			        		$.each(result.data.list, function(k, v) {
			        			html+='<option value="'+v.goods_id+'">'+v.zh_name+'('+v.en_name+')</option>';
			        		});
			        		$("#goods_id").html(html);
		        		}
		        		
		        	}else{
		        		parent.layer.msg(result.message);
		        		return false;
		        	}
		        }
		   });
   		 }else{
   		 	parent.layer.msg("商品名称丶商品条码丶商品货号丶商品助记码至少填一个！");
   		 }
   });
      $("#submit").click(function(){
      	var goods_id = $('#goods_id').val();
      	if(goods_id > 0){
      		ajax_post(ApiUrl + "/order/cart","cart.html","goods_id="+goods_id);
      	}else{
      		parent.layer.msg("请选择商品后点击提交！");
		    return false;
      	}
      });
});